
<template>
    <el-card>
      <div class="title-flex">
        <div>专家评审列表</div>
      </div>
    </el-card>
    <el-card style="margin-top: 10px">
      <el-button type="primary"  @click="submitSbtn()">提交</el-button>
      <el-table
          :data="tableData"
          style="width: 100%;margin-top: 10px"
          @selection-change="handleSelectionChange"
          ref="tableRef"
          :selectable="isSelectable"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="bookName" label="项目名称"></el-table-column>
        <el-table-column prop="typeName" label="项目分类"></el-table-column>
        <el-table-column prop="endDate" label="计划结束日期">
          <template #default="{ row }">
            {{ new Date(row.endDate).toLocaleDateString() }}
          </template>
        </el-table-column>
        <el-table-column prop="applyFee" label="申请经费（万元）"></el-table-column>
        <el-table-column prop="reviewStatus" label="评审状态">
          <template #default="{ row }">
            {{ getReviewStatusText(row.reviewStatus) }}
          </template>
        </el-table-column>
        <el-table-column prop="reviewMark" label="评审分值"></el-table-column>
        <el-table-column label="操作" width="150">
          <template #default="scope">
            <el-button v-if="scope.row.reviewStatus =='notReview'||scope.row.reviewStatus =='notSubmit'" type="primary" size="small" plain @click="openspecialistDetails(scope.row)">评审</el-button>
            <el-button v-if="scope.row.reviewStatus =='notSubmit'" type="primary" size="small" plain @click="submitBtn(scope.row)">提交</el-button>
            <el-button v-if="scope.row.reviewStatus =='notReview'" type="primary" size="small" plain @click="NoSubmit(scope.row)">拒评</el-button></template>
        </el-table-column>
      </el-table>
<!--      <div class="example-pagination-block">-->
<!--        <el-pagination-->
<!--            layout="->,prev, pager, next, total"-->
<!--            :total="count"-->
<!--            currentPage1="10"-->
<!--            @current-change="handleCurrentChange"-->
<!--        />-->
<!--      </div>-->
    </el-card>
  <specialistDetails ref="specialistDetailsRef" @Getlist="getlist"></specialistDetails>

  <el-dialog v-model="dialogTableVisible" title="拒评理由" width="600">
    <el-input v-model="reviewInfo" type="textarea" />
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="dialogsubmit">提交</el-button>
        <el-button @click="dialogTableVisible = false">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import {onMounted, ref} from 'vue';
import {myreview,submit,refuse} from './../../api/specialist/specialistApi.js'
import specialistDetails from './specialistDetails.vue'
import {ElMessage, ElMessageBox} from "element-plus";
const specialistDetailsRef = ref(null)
const openspecialistDetails = function (row){
  specialistDetailsRef.value.open(row)
}

const tableRef = ref(null);
const tableData = ref([
  // {
  //   bookName: 'INFO_1_POSTMAN 白雪book1',
  //   typeName: '13031测试的项目分类',
  //   endDate: 4075977600000,
  //   applyFee: '33.3',
  //   reviewStatus: 'notReview',
  //   reviewScore: '',
  //   expertReviewId: '专家评审测试_1'
  // }
]);
//
const dialogTableVisible = ref(false)
const reviewInfo = ref('')
//拒绝评审
const NoSubmit = (row)=>{
  dialogTableVisible.value = true
  rows.value = row.expertReviewId
}
const rows = ref('')
//弹窗确认按钮
const dialogsubmit = ()=>{
  refuse({
    "expertReviewId": rows.value,
    "reviewInfo": reviewInfo.value
  })
      .then((res)=>{
        if(res.code == 200){
          ElMessage({
            type: 'success',
            message: res.msg,
          })
          getlist()
          dialogTableVisible.value = false
        }else {
          ElMessage({
            type: 'info',
            message: res.msg,
          })
        }
      })
}

//多选
const multipleSelection = ref([]);

const handleSelectionChange = (val) => {
  multipleSelection.value = val;
};
//分页
const count = ref('0')
const handleCurrentChange = (val) => {

}
//列提交按钮
const submitBtn = (row) => {
    ElMessageBox.confirm(
        '是否确认提交评审内容？',
        'Warning',
        {
          confirmButtonText: '提交',
          cancelButtonText: '不提交',
          type: '提示',
        }
    )
        .then(() => {
          submit({
            ids:[row.expertReviewId]
          })
              .then((res)=>{
                if(res.code == 200){
                  ElMessage({
                    type: 'success',
                    message: res.msg,
                  })
                  getlist()
                }
              })
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: '取消提交',
          })
        })

  //console.log('操作行数据:', row);
};
const submitSbtn = () => {
  ElMessageBox.confirm(
      '是否确认批量提交评审内容？',
      '提示',
      {
        confirmButtonText: '提交',
        cancelButtonText: '不提交',
        type: '提示',
      }
  )
      .then(() => {
        let ids = multipleSelection.value.map(item => item.expertReviewId)
        console.log(ids)
        if (ids.length === 0) {
          ElMessage({
            type: 'error',
            message: '没有可提交的评审内容',
          });
          return;
        }
        submit({
          ids:ids
        })
            .then((res)=>{
              if(res.code == 200){
                ElMessage({
                  type: 'success',
                  message: res.msg,
                })
                getlist()
              }
            })
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '取消提交',
        })
      })

}
const handleAction = (row) => {

  console.log('操作行数据:', row);
};
//评审状态
const getReviewStatusText = (status) => {
  switch (status) {
    case 'notReview':
      return '未评审';
    case 'notSubmit':
      return '未提交';
    case 'submit':
      return '已提交';
    case 'refuseReview':
      return '拒评';
    default:
      return status;
  }
};
//notReview 未评审 notSubmit 未提交 submit 已提交 refuseReview 拒评
const isSelectable = (row) => {
  return row.reviewStatus === 'notSubmit';
};

const getlist = ()=>{
  myreview({
    type:'todo',
    pageSize:'9999',
    pageNum:'1'
  })
      .then((res)=>{
        count.value = res.total
        tableData.value = res.rows
      })
}

onMounted(()=>{
  myreview({
    type:'todo',
    pageSize:'9999',
    pageNum:'1'
  })
      .then((res)=>{
         count.value = res.total
        tableData.value = res.rows
      })
})

</script>

<style scoped lang="scss">
.title-flex{
  display: flex;
  justify-content: space-between;
  text-align: center;

}
.dialog-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
}
</style>